package com.ruoyi.tb.lmt.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.domain.PageQuery;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import com.ruoyi.tb.lmt.domain.bo.DrDamperDataBo;
import com.ruoyi.tb.lmt.domain.vo.DrDamperDataVo;
import com.ruoyi.tb.lmt.domain.DrDamperData;
import com.ruoyi.tb.lmt.mapper.DrDamperDataMapper;
import com.ruoyi.tb.lmt.service.IDrDamperDataService;

import java.time.LocalDate;
import java.util.List;
import java.util.Map;
import java.util.Collection;

/**
 * 油压减震器Service业务层处理
 *
 * @author ruoyi
 * @date 2023-12-13
 */
@RequiredArgsConstructor
@Service
public class DrDamperDataServiceImpl implements IDrDamperDataService {

    private final DrDamperDataMapper baseMapper;

    /**
     * 查询油压减震器
     */
    @Override
    public DrDamperDataVo queryById(Long id) {
        return baseMapper.selectVoById(id);
    }

    /**
     * 查询油压减震器列表
     */
    @Override
    public TableDataInfo<DrDamperDataVo> queryPageList(DrDamperDataBo bo, PageQuery pageQuery) {
        LambdaQueryWrapper<DrDamperData> lqw = buildQueryWrapper(bo);
        Page<DrDamperDataVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
        return TableDataInfo.build(result);
    }

    /**
     * 查询油压减震器列表
     */
    @Override
    public List<DrDamperDataVo> queryList(DrDamperDataBo bo) {
        LambdaQueryWrapper<DrDamperData> lqw = buildQueryWrapper(bo);
        return baseMapper.selectVoList(lqw);
    }

    private LambdaQueryWrapper<DrDamperData> buildQueryWrapper(DrDamperDataBo bo) {
        Map<String, Object> params = bo.getParams();
        LambdaQueryWrapper<DrDamperData> lqw = Wrappers.lambdaQuery();
        lqw.eq(bo.getId() != null, DrDamperData::getId, bo.getId());
        lqw.eq(StringUtils.isNotBlank(bo.getDjNo()), DrDamperData::getDjNo, bo.getDjNo());
        lqw.eq(bo.getDrId() != null, DrDamperData::getDrId, bo.getDrId());
        lqw.eq(StringUtils.isNotBlank(bo.getDrDamperNo()), DrDamperData::getDrDamperNo, bo.getDrDamperNo());
        lqw.eq(StringUtils.isNotBlank(bo.getDrDamperType()), DrDamperData::getDrDamperType, bo.getDrDamperType());
        lqw.eq(StringUtils.isNotBlank(bo.getDrCarNo()), DrDamperData::getDrCarNo, bo.getDrCarNo());
        lqw.eq(StringUtils.isNotBlank(bo.getDrCarType()), DrDamperData::getDrCarType, bo.getDrCarType());
        lqw.eq(StringUtils.isNotBlank(bo.getDrProduceDate()), DrDamperData::getDrProduceDate, bo.getDrProduceDate());
        lqw.eq(StringUtils.isNotBlank(bo.getDrLastTestDate()), DrDamperData::getDrLastTestDate, bo.getDrLastTestDate());
        lqw.eq(StringUtils.isNotBlank(bo.getDrUsedMonth()), DrDamperData::getDrUsedMonth, bo.getDrUsedMonth());
        lqw.eq(StringUtils.isNotBlank(bo.getDrUsedLength()), DrDamperData::getDrUsedLength, bo.getDrUsedLength());
        lqw.eq(StringUtils.isNotBlank(bo.getDrFV()), DrDamperData::getDrFV, bo.getDrFV());
        lqw.eq(StringUtils.isNotBlank(bo.getDrAmplititude()), DrDamperData::getDrAmplititude, bo.getDrAmplititude());
        lqw.eq(StringUtils.isNotBlank(bo.getDrFriquency()), DrDamperData::getDrFriquency, bo.getDrFriquency());
        lqw.eq(StringUtils.isNotBlank(bo.getDrVelocityInterval()), DrDamperData::getDrVelocityInterval, bo.getDrVelocityInterval());
        lqw.eq(StringUtils.isNotBlank(bo.getDrTotalResult()), DrDamperData::getDrTotalResult, bo.getDrTotalResult());
        lqw.eq(StringUtils.isNotBlank(bo.getDrTestDate()), DrDamperData::getDrTestDate, bo.getDrTestDate());
        lqw.eq(StringUtils.isNotBlank(bo.getDrOperator()), DrDamperData::getDrOperator, bo.getDrOperator());
        lqw.eq(StringUtils.isNotBlank(bo.getDrChecker()), DrDamperData::getDrChecker, bo.getDrChecker());
        lqw.eq(StringUtils.isNotBlank(bo.getDrTestSetNum()), DrDamperData::getDrTestSetNum, bo.getDrTestSetNum());
        lqw.eq(StringUtils.isNotBlank(bo.getDrVelocitySet0()), DrDamperData::getDrVelocitySet0, bo.getDrVelocitySet0());
        lqw.eq(StringUtils.isNotBlank(bo.getDrFtset0()), DrDamperData::getDrFtset0, bo.getDrFtset0());
        lqw.eq(StringUtils.isNotBlank(bo.getDrFpset0()), DrDamperData::getDrFpset0, bo.getDrFpset0());
        lqw.eq(StringUtils.isNotBlank(bo.getDrErrPset0()), DrDamperData::getDrErrPset0, bo.getDrErrPset0());
        lqw.eq(StringUtils.isNotBlank(bo.getDrErrNset0()), DrDamperData::getDrErrNset0, bo.getDrErrNset0());
        lqw.eq(StringUtils.isNotBlank(bo.getDrDissymmetrySet0()), DrDamperData::getDrDissymmetrySet0, bo.getDrDissymmetrySet0());
        lqw.eq(StringUtils.isNotBlank(bo.getDrVelocitySet1()), DrDamperData::getDrVelocitySet1, bo.getDrVelocitySet1());
        lqw.eq(StringUtils.isNotBlank(bo.getDrFtset1()), DrDamperData::getDrFtset1, bo.getDrFtset1());
        lqw.eq(StringUtils.isNotBlank(bo.getDrFpset1()), DrDamperData::getDrFpset1, bo.getDrFpset1());
        lqw.eq(StringUtils.isNotBlank(bo.getDrErrPset1()), DrDamperData::getDrErrPset1, bo.getDrErrPset1());
        lqw.eq(StringUtils.isNotBlank(bo.getDrErrNset1()), DrDamperData::getDrErrNset1, bo.getDrErrNset1());
        lqw.eq(StringUtils.isNotBlank(bo.getDrDissymmetrySet1()), DrDamperData::getDrDissymmetrySet1, bo.getDrDissymmetrySet1());
        lqw.eq(StringUtils.isNotBlank(bo.getDrVelocitySet2()), DrDamperData::getDrVelocitySet2, bo.getDrVelocitySet2());
        lqw.eq(StringUtils.isNotBlank(bo.getDrFtset2()), DrDamperData::getDrFtset2, bo.getDrFtset2());
        lqw.eq(StringUtils.isNotBlank(bo.getDrFpset2()), DrDamperData::getDrFpset2, bo.getDrFpset2());
        lqw.eq(StringUtils.isNotBlank(bo.getDrErrPset2()), DrDamperData::getDrErrPset2, bo.getDrErrPset2());
        lqw.eq(StringUtils.isNotBlank(bo.getDrErrNset2()), DrDamperData::getDrErrNset2, bo.getDrErrNset2());
        lqw.eq(StringUtils.isNotBlank(bo.getDrDissymmetrySet2()), DrDamperData::getDrDissymmetrySet2, bo.getDrDissymmetrySet2());
        lqw.eq(StringUtils.isNotBlank(bo.getDrVelocitySet3()), DrDamperData::getDrVelocitySet3, bo.getDrVelocitySet3());
        lqw.eq(StringUtils.isNotBlank(bo.getDrFtset3()), DrDamperData::getDrFtset3, bo.getDrFtset3());
        lqw.eq(StringUtils.isNotBlank(bo.getDrFpset3()), DrDamperData::getDrFpset3, bo.getDrFpset3());
        lqw.eq(StringUtils.isNotBlank(bo.getDrErrPset3()), DrDamperData::getDrErrPset3, bo.getDrErrPset3());
        lqw.eq(StringUtils.isNotBlank(bo.getDrErrNset3()), DrDamperData::getDrErrNset3, bo.getDrErrNset3());
        lqw.eq(StringUtils.isNotBlank(bo.getDrDissymmetrySet3()), DrDamperData::getDrDissymmetrySet3, bo.getDrDissymmetrySet3());
        lqw.eq(StringUtils.isNotBlank(bo.getDrVelocitySet4()), DrDamperData::getDrVelocitySet4, bo.getDrVelocitySet4());
        lqw.eq(StringUtils.isNotBlank(bo.getDrFtset4()), DrDamperData::getDrFtset4, bo.getDrFtset4());
        lqw.eq(StringUtils.isNotBlank(bo.getDrFpset4()), DrDamperData::getDrFpset4, bo.getDrFpset4());
        lqw.eq(StringUtils.isNotBlank(bo.getDrErrPset4()), DrDamperData::getDrErrPset4, bo.getDrErrPset4());
        lqw.eq(StringUtils.isNotBlank(bo.getDrErrNset4()), DrDamperData::getDrErrNset4, bo.getDrErrNset4());
        lqw.eq(StringUtils.isNotBlank(bo.getDrDissymmetrySet4()), DrDamperData::getDrDissymmetrySet4, bo.getDrDissymmetrySet4());
        lqw.eq(StringUtils.isNotBlank(bo.getDrDt0()), DrDamperData::getDrDt0, bo.getDrDt0());
        lqw.eq(StringUtils.isNotBlank(bo.getDrDt1()), DrDamperData::getDrDt1, bo.getDrDt1());
        lqw.eq(StringUtils.isNotBlank(bo.getDrDt2()), DrDamperData::getDrDt2, bo.getDrDt2());
        lqw.eq(StringUtils.isNotBlank(bo.getDrDt3()), DrDamperData::getDrDt3, bo.getDrDt3());
        lqw.eq(StringUtils.isNotBlank(bo.getDrDt4()), DrDamperData::getDrDt4, bo.getDrDt4());
        lqw.eq(StringUtils.isNotBlank(bo.getDrDamperData00()), DrDamperData::getDrDamperData00, bo.getDrDamperData00());
        lqw.eq(StringUtils.isNotBlank(bo.getDrDamperData01()), DrDamperData::getDrDamperData01, bo.getDrDamperData01());
        lqw.eq(StringUtils.isNotBlank(bo.getDrDamperData10()), DrDamperData::getDrDamperData10, bo.getDrDamperData10());
        lqw.eq(StringUtils.isNotBlank(bo.getDrDamperData11()), DrDamperData::getDrDamperData11, bo.getDrDamperData11());
        lqw.eq(StringUtils.isNotBlank(bo.getDrDamperData20()), DrDamperData::getDrDamperData20, bo.getDrDamperData20());
        lqw.eq(StringUtils.isNotBlank(bo.getDrDamperData21()), DrDamperData::getDrDamperData21, bo.getDrDamperData21());
        lqw.eq(StringUtils.isNotBlank(bo.getDrDamperData30()), DrDamperData::getDrDamperData30, bo.getDrDamperData30());
        lqw.eq(StringUtils.isNotBlank(bo.getDrDamperData31()), DrDamperData::getDrDamperData31, bo.getDrDamperData31());
        lqw.eq(StringUtils.isNotBlank(bo.getDrDamperData40()), DrDamperData::getDrDamperData40, bo.getDrDamperData40());
        lqw.eq(StringUtils.isNotBlank(bo.getDrDamperData41()), DrDamperData::getDrDamperData41, bo.getDrDamperData41());
        lqw.eq(StringUtils.isNotBlank(bo.getDrTestAmplitude0()), DrDamperData::getDrTestAmplitude0, bo.getDrTestAmplitude0());
        lqw.eq(StringUtils.isNotBlank(bo.getDrVelocityTension0()), DrDamperData::getDrVelocityTension0, bo.getDrVelocityTension0());
        lqw.eq(StringUtils.isNotBlank(bo.getDrFtesion0()), DrDamperData::getDrFtesion0, bo.getDrFtesion0());
        lqw.eq(StringUtils.isNotBlank(bo.getDrErrFtension0()), DrDamperData::getDrErrFtension0, bo.getDrErrFtension0());
        lqw.eq(StringUtils.isNotBlank(bo.getDrResultTension0()), DrDamperData::getDrResultTension0, bo.getDrResultTension0());
        lqw.eq(StringUtils.isNotBlank(bo.getDrVelocityPress0()), DrDamperData::getDrVelocityPress0, bo.getDrVelocityPress0());
        lqw.eq(StringUtils.isNotBlank(bo.getDrFpress()), DrDamperData::getDrFpress, bo.getDrFpress());
        lqw.eq(StringUtils.isNotBlank(bo.getDrErrEpress0()), DrDamperData::getDrErrEpress0, bo.getDrErrEpress0());
        lqw.eq(StringUtils.isNotBlank(bo.getDrResultPress0()), DrDamperData::getDrResultPress0, bo.getDrResultPress0());
        lqw.eq(StringUtils.isNotBlank(bo.getDrDissymmetry0()), DrDamperData::getDrDissymmetry0, bo.getDrDissymmetry0());
        lqw.eq(StringUtils.isNotBlank(bo.getDrResultDissymmetry0()), DrDamperData::getDrResultDissymmetry0, bo.getDrResultDissymmetry0());
        lqw.eq(StringUtils.isNotBlank(bo.getDrFV0()), DrDamperData::getDrFV0, bo.getDrFV0());
        lqw.eq(StringUtils.isNotBlank(bo.getDrTestResult0()), DrDamperData::getDrTestResult0, bo.getDrTestResult0());
        lqw.eq(StringUtils.isNotBlank(bo.getDrTestAmplitude1()), DrDamperData::getDrTestAmplitude1, bo.getDrTestAmplitude1());
        lqw.eq(StringUtils.isNotBlank(bo.getDrVelocityTension1()), DrDamperData::getDrVelocityTension1, bo.getDrVelocityTension1());
        lqw.eq(StringUtils.isNotBlank(bo.getDrFtension1()), DrDamperData::getDrFtension1, bo.getDrFtension1());
        lqw.eq(StringUtils.isNotBlank(bo.getDrErrFtension1()), DrDamperData::getDrErrFtension1, bo.getDrErrFtension1());
        lqw.eq(StringUtils.isNotBlank(bo.getDrResultTension1()), DrDamperData::getDrResultTension1, bo.getDrResultTension1());
        lqw.eq(StringUtils.isNotBlank(bo.getDrVelocitypress1()), DrDamperData::getDrVelocitypress1, bo.getDrVelocitypress1());
        lqw.eq(StringUtils.isNotBlank(bo.getDrFpress1()), DrDamperData::getDrFpress1, bo.getDrFpress1());
        lqw.eq(StringUtils.isNotBlank(bo.getDrErrFpress1()), DrDamperData::getDrErrFpress1, bo.getDrErrFpress1());
        lqw.eq(StringUtils.isNotBlank(bo.getDrResultPress1()), DrDamperData::getDrResultPress1, bo.getDrResultPress1());
        lqw.eq(StringUtils.isNotBlank(bo.getDrDissymmetry1()), DrDamperData::getDrDissymmetry1, bo.getDrDissymmetry1());
        lqw.eq(StringUtils.isNotBlank(bo.getDrResultDissymmetry1()), DrDamperData::getDrResultDissymmetry1, bo.getDrResultDissymmetry1());
        lqw.eq(StringUtils.isNotBlank(bo.getDrFV1()), DrDamperData::getDrFV1, bo.getDrFV1());
        lqw.eq(StringUtils.isNotBlank(bo.getDrTestResult1()), DrDamperData::getDrTestResult1, bo.getDrTestResult1());
        lqw.eq(StringUtils.isNotBlank(bo.getDrTestAmplitude2()), DrDamperData::getDrTestAmplitude2, bo.getDrTestAmplitude2());
        lqw.eq(StringUtils.isNotBlank(bo.getDrVelocityTension2()), DrDamperData::getDrVelocityTension2, bo.getDrVelocityTension2());
        lqw.eq(StringUtils.isNotBlank(bo.getDrFtension2()), DrDamperData::getDrFtension2, bo.getDrFtension2());
        lqw.eq(StringUtils.isNotBlank(bo.getDrErrFtension2()), DrDamperData::getDrErrFtension2, bo.getDrErrFtension2());
        lqw.eq(StringUtils.isNotBlank(bo.getDrResultTension2()), DrDamperData::getDrResultTension2, bo.getDrResultTension2());
        lqw.eq(StringUtils.isNotBlank(bo.getDrVelocityPress2()), DrDamperData::getDrVelocityPress2, bo.getDrVelocityPress2());
        lqw.eq(StringUtils.isNotBlank(bo.getDrFpress2()), DrDamperData::getDrFpress2, bo.getDrFpress2());
        lqw.eq(StringUtils.isNotBlank(bo.getDrErrFpress2()), DrDamperData::getDrErrFpress2, bo.getDrErrFpress2());
        lqw.eq(StringUtils.isNotBlank(bo.getDrResultPress2()), DrDamperData::getDrResultPress2, bo.getDrResultPress2());
        lqw.eq(StringUtils.isNotBlank(bo.getDrDissymmetry2()), DrDamperData::getDrDissymmetry2, bo.getDrDissymmetry2());
        lqw.eq(StringUtils.isNotBlank(bo.getDrResultDissymmetry2()), DrDamperData::getDrResultDissymmetry2, bo.getDrResultDissymmetry2());
        lqw.eq(StringUtils.isNotBlank(bo.getDrFV2()), DrDamperData::getDrFV2, bo.getDrFV2());
        lqw.eq(StringUtils.isNotBlank(bo.getDrTestResult2()), DrDamperData::getDrTestResult2, bo.getDrTestResult2());
        lqw.eq(StringUtils.isNotBlank(bo.getDrTestAmplitude3()), DrDamperData::getDrTestAmplitude3, bo.getDrTestAmplitude3());
        lqw.eq(StringUtils.isNotBlank(bo.getDrVelocityTension3()), DrDamperData::getDrVelocityTension3, bo.getDrVelocityTension3());
        lqw.eq(StringUtils.isNotBlank(bo.getDrFtension3()), DrDamperData::getDrFtension3, bo.getDrFtension3());
        lqw.eq(StringUtils.isNotBlank(bo.getDrErrFtension3()), DrDamperData::getDrErrFtension3, bo.getDrErrFtension3());
        lqw.eq(StringUtils.isNotBlank(bo.getDrResultTension3()), DrDamperData::getDrResultTension3, bo.getDrResultTension3());
        lqw.eq(StringUtils.isNotBlank(bo.getDrVelocityPress3()), DrDamperData::getDrVelocityPress3, bo.getDrVelocityPress3());
        lqw.eq(StringUtils.isNotBlank(bo.getDrFpress3()), DrDamperData::getDrFpress3, bo.getDrFpress3());
        lqw.eq(StringUtils.isNotBlank(bo.getDrErrFpress3()), DrDamperData::getDrErrFpress3, bo.getDrErrFpress3());
        lqw.eq(StringUtils.isNotBlank(bo.getDrResultPress3()), DrDamperData::getDrResultPress3, bo.getDrResultPress3());
        lqw.eq(StringUtils.isNotBlank(bo.getDrDissymmetry3()), DrDamperData::getDrDissymmetry3, bo.getDrDissymmetry3());
        lqw.eq(StringUtils.isNotBlank(bo.getDrResultDissymmetry3()), DrDamperData::getDrResultDissymmetry3, bo.getDrResultDissymmetry3());
        lqw.eq(StringUtils.isNotBlank(bo.getDrFV3()), DrDamperData::getDrFV3, bo.getDrFV3());
        lqw.eq(StringUtils.isNotBlank(bo.getDrTestResult3()), DrDamperData::getDrTestResult3, bo.getDrTestResult3());
        lqw.eq(StringUtils.isNotBlank(bo.getDrTestAmplitude4()), DrDamperData::getDrTestAmplitude4, bo.getDrTestAmplitude4());
        lqw.eq(StringUtils.isNotBlank(bo.getDrVelocityTension4()), DrDamperData::getDrVelocityTension4, bo.getDrVelocityTension4());
        lqw.eq(StringUtils.isNotBlank(bo.getDrFtension4()), DrDamperData::getDrFtension4, bo.getDrFtension4());
        lqw.eq(StringUtils.isNotBlank(bo.getDrErrFtension4()), DrDamperData::getDrErrFtension4, bo.getDrErrFtension4());
        lqw.eq(StringUtils.isNotBlank(bo.getDrResultTension4()), DrDamperData::getDrResultTension4, bo.getDrResultTension4());
        lqw.eq(StringUtils.isNotBlank(bo.getDrVelocityPress4()), DrDamperData::getDrVelocityPress4, bo.getDrVelocityPress4());
        lqw.eq(StringUtils.isNotBlank(bo.getDrFpress4()), DrDamperData::getDrFpress4, bo.getDrFpress4());
        lqw.eq(StringUtils.isNotBlank(bo.getDrErrFpress4()), DrDamperData::getDrErrFpress4, bo.getDrErrFpress4());
        lqw.eq(StringUtils.isNotBlank(bo.getDrResultPress4()), DrDamperData::getDrResultPress4, bo.getDrResultPress4());
        lqw.eq(StringUtils.isNotBlank(bo.getDrDissymmmetry4()), DrDamperData::getDrDissymmmetry4, bo.getDrDissymmmetry4());
        lqw.eq(StringUtils.isNotBlank(bo.getDrResultDissymmetry4()), DrDamperData::getDrResultDissymmetry4, bo.getDrResultDissymmetry4());
        lqw.eq(StringUtils.isNotBlank(bo.getDrFV4()), DrDamperData::getDrFV4, bo.getDrFV4());
        lqw.eq(StringUtils.isNotBlank(bo.getDrTestResult4()), DrDamperData::getDrTestResult4, bo.getDrTestResult4());
        lqw.eq(StringUtils.isNotBlank(bo.getDrRemark()), DrDamperData::getDrRemark, bo.getDrRemark());
        lqw.eq(StringUtils.isNotBlank(bo.getDelFlag()), DrDamperData::getDelFlag, bo.getDelFlag());
        lqw.eq(StringUtils.isNotBlank(bo.getCreateBy()), DrDamperData::getCreateBy, bo.getCreateBy());
        lqw.eq(bo.getCreateTime() != null, DrDamperData::getCreateTime, bo.getCreateTime());
        lqw.eq(StringUtils.isNotBlank(bo.getUpdateBy()), DrDamperData::getUpdateBy, bo.getUpdateBy());
        lqw.eq(bo.getUpdateTime() != null, DrDamperData::getUpdateTime, bo.getUpdateTime());
        return lqw;
    }

    /**
     * 新增油压减震器
     */
    @Override
    public Boolean insertByBo(DrDamperDataBo bo) {
        DrDamperData add = BeanUtil.toBean(bo, DrDamperData.class);
        add.setDelFlag("0");
        validEntityBeforeSave(add);
        boolean flag = baseMapper.insert(add) > 0;
        if (flag) {
            bo.setId(add.getId());
        }
        return flag;
    }

    /**
     * 修改油压减震器
     */
    @Override
    public Boolean updateByBo(DrDamperDataBo bo) {
        DrDamperData update = BeanUtil.toBean(bo, DrDamperData.class);
        validEntityBeforeSave(update);
        return baseMapper.updateById(update) > 0;
    }

    /**
     * 保存前的数据校验
     */
    private void validEntityBeforeSave(DrDamperData entity) {
        //TODO 做一些数据校验,如唯一约束
    }

    /**
     * 批量删除油压减震器
     */
    @Override
    public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
        if (isValid) {
            //TODO 做一些业务上的校验,判断是否需要校验
        }
        return baseMapper.deleteBatchIds(ids) > 0;
    }

    @Override
    public Long getMaxDrID() {

        return baseMapper.getMaxDrID();
    }

    @Override
    public List<DrDamperData> selectListByDate(LocalDate date) {

        return baseMapper.selectListByDate(date);
    }
}
